function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()


  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}

function generateCollectId(time) {
  return 'id-col' + time;
}

function generateItemId(time) {
  return 'id-item' + time;
}

function px2rpx(px, windowWidth) {
  return Math.round(px * 750 / windowWidth);
}

function rpx2px(rpx, windowWidth) {
  return Math.round(rpx / 750 * windowWidth);
}

function copy(target, source, strict) {
  for(var key in source){
    if(!strict || target.hasOwnProperty(key) || target[key] !== undefined){
      target[key] = source[key];
    }
  }
  return target;
}
var SHOW_TYPE_COLLECT = 1;
var SHOW_TYPE_ITEM = 2;
var TYPE_COLLECT = 0;
var TYPE_ITEM = 1;
var STATE_NORMAL = 0;
var STATE_DONE = 1;
var STATE_DELETE = 2;
var COLOR_WHITE = '#fff';
var COLOR_BLACK = '#000';
var COLOR_DONE = 'RGB(16, 170, 22)';
var COLOR_GRAY = '#666';
var LOOP_INTEVAL = 4;
var TOUCH_ACTION_NONE = 0;
var TOUCH_ACTION_LIST = 1;
var TOUCH_ACTION_ITEM = 2;
var TOUCH_ACTION_SORT = 3;
var SORT_MOVE_SPEED = 4.5

module.exports = {
  formatTime: formatTime,
  generateCollectId: generateCollectId,
  generateItemId: generateItemId,
  px2rpx: px2rpx,
  rpx2px: rpx2px,
  copy:copy,
  SHOW_TYPE_COLLECT: SHOW_TYPE_COLLECT,
  SHOW_TYPE_ITEM: SHOW_TYPE_ITEM,
  TYPE_COLLECT: TYPE_COLLECT,
  TYPE_ITEM: TYPE_ITEM,
  STATE_NORMAL: STATE_NORMAL,
  STATE_DONE: STATE_DONE,
  STATE_DELETE: STATE_DELETE,
  COLOR_WHITE:COLOR_WHITE,
  COLOR_BLACK: COLOR_BLACK,
  COLOR_DONE: COLOR_DONE,
  COLOR_GRAY: COLOR_GRAY,
  LOOP_INTEVAL: LOOP_INTEVAL,
  TOUCH_ACTION_NONE: TOUCH_ACTION_NONE,
  TOUCH_ACTION_LIST: TOUCH_ACTION_LIST,
  TOUCH_ACTION_ITEM: TOUCH_ACTION_ITEM,
  TOUCH_ACTION_SORT: TOUCH_ACTION_SORT,
  SORT_MOVE_SPEED: SORT_MOVE_SPEED
}
